import socket
import sys
from time import ctime,sleep
from compiler.pycodegen import EXCEPT
host=['www.dapu.com','www.baidu.com','ocs.dapu.com']
ports="80"
def write_file(the_txt):
    s_file=open('check_http.log','a')
    s_file.write(the_txt)
def check_web(address,port):
    s=socket.socket()
    s.settimeout(10)
    try:
        s.connect((address,int(port)))
        the_log=ctime()+"the server is ok "+address+":"+port+'\n'
        write_file(the_log)
#        print ctime()+"the server is ok "+address+":"+port
    except:
        print ctime()+"error"+address+":"+port
        
    s.close()
counts=range(len(host))
#print counts
if __name__=="__main__":
    while True:
        for i in counts:
            check_web(host[i], ports)
            sleep(10)
    
#while True:
#    check_web(host, ports)
#    sleep(50)
    